package com.benbi.shequapi.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.benbi.shequapi.bean.*;
import com.benbi.shequapi.mapper.*;
import com.benbi.shequapi.service.TasksService;
import com.benbi.shequapi.utils.Result;
import com.benbi.shequapi.utils.ResultData;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class TasksImpl implements TasksService {
    @Resource
    TasksMapper tasksMapper;


    @Override
    public Result getTasksList() {

        List<Tasks> resultList;
        resultList = tasksMapper.selectTasksList();
        if (resultList == null) {return new Result(1, "不存在任务");}
        return new ResultData(resultList);
    }

    @Override
    public Result getTasksByTaskid(int task_id) {
        Tasks p = tasksMapper.selectTasksByTaskid(task_id);
        if (p == null) {return new Result(1, "不存在该任务");}
        return new ResultData(p);
    }

    @Override
    public Result newTasks(int a_pid,int top,String title,String content) {
        Date d = new Date();
        Tasks t = new Tasks(0,a_pid,top,title,content,d);
        int p = tasksMapper.insertTasks(t);
        return new Result(0, "成功");
    }

    @Override
    public Result deleteTasks(int task_id){
        int p = tasksMapper.deleteTasksByTaskid(task_id);
        return new Result(0, "成功");
    }



}
